<?php
	if (!session_start()) session_start();
	if (!isset($_SESSION['kiemtradangnhapanan']) || $_SESSION['kiemtradangnhapanan']!=1) {
		header('location: ../../../index.php');
		die();
	}
	$table = "donhang";
	$id = $_GET['id'];
	$kq=$qt->get_by_thutu($table,$id);
	$record=mysql_fetch_assoc($kq);
	if(isset($_POST['ok']))
	{	
		$id=$_POST['id'];
		//echo $id;die;
		$field = array('daxuly','datratien');
		
		$now = getdate();
		$ngay = $now["year"]."-".$now["mon"]."-".$now["mday"]." ".$now["hours"].":".$now["minutes"].":".$now["seconds"];
		
		$values= array( format($_POST["daxuly"],0),
		 format($_POST["datratien"],0)
		);
		//print_r ($values);die;
		$res=$qt->updateObject($table,$field,$values,"id='$id'");
		
		if($res){
			echo "<script>alert('Sửa dữ liệu thành công !!!');history.go(-2);</script>";
		}
	}
?>				
<script type="text/javascript">
function isTest() {
	if (document.getElementById("ten_vi").value=="") {
		alert("You have not entered enough information.");
		return false;
	}
	if (document.getElementById("ten_en").value=="") {
		alert("You have not entered enough information.");
		return false;
	}
	
    return true;
}	
</script>	
            	<div class="dangnhap_title">
                <a href="index.php" style="color:#F8991D;" title="Trang chủ">Trang chủ</a>
                <span style="font-size:9px;">>></span> 
                Sản phẩm
                <span style="font-size:9px;">>></span> 
                <a href="index.php?p=<?php echo $table; ?>_quanly" style="color:#F8991D;">Đơn hàng</a> 
            	</div>
            	<form method="post" action="index.php?p=<?php echo $table; ?>_sua" onSubmit="return isTest();">
            	<input type="hidden" name="id" value="<?php echo $id; ?>" />
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="font-size:22px; color:#0E6BBB; width: 90%;">
                        Vietnamese's Information
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Người nhận hàng
                    </div>
                    <div class="dangnhap_col_input">
                        <?php echo $record['tennguoinhan']; ?>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Thời điểm giao hàng
                    </div>
                    <div class="dangnhap_col_input">
                        <?php echo date('d/m/Y',strtotime($record['thoidiemnhanhang'])); ?>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Điện thoại người nhận hàng
                    </div>
                    <div class="dangnhap_col_input">
                        <?php echo $record['dtnguoinhan']; ?>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Địa chỉ người nhận
                    </div>
                    <div class="dangnhap_col_input">
                         <?php echo $record['diachi']; ?>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Ghi chú
                    </div>
                    <div class="dangnhap_col_input">
                         <?php echo $record['ghichu']; ?>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Tổng tiền
                    </div>
                    <div class="dangnhap_col_input">
                         <?=number_format($record['tongtien'],0,",",".")?>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Đã xử lý
                    </div>
                    <div class="dangnhap_col_input">
                         <select name="daxuly" id="daxyly">
					<? if($record['daxuly']==0) {?>
                    <option value="0">Chưa duyệt</option>
                    <option value="1">Đã duyệt</option>
                    <? } else {?>
                    <option value="1">Đã duyệt</option>
                    <? }?>
                	</select>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title">
                        &nbsp; &nbsp; &nbsp;- Đã thanh toán
                    </div>
                    <div class="dangnhap_col_input">
                         <select name="datratien" id="datratien">
					<? if($record['datratien']==0) {?>
                    <option value="0">Chưa thanh toán</option>
                    <option value="1">Đã thanh toán</option>
                    <? } else {?>
                    <option value="1">Đã thanh toán</option>
                    <? }?>
                	</select>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_input">
                        <input type="submit" class="ok" border="0" name="ok" id="ok" value="" />
                        <a href="javascript:history.go(-1);"><img src="imgs/exit_button.png" border="0" /></a>
                    </div>
                </div>
                <div class="dangnhap_col">
                    <div class="dangnhap_col_title" style="font-size:22px; color:#0E6BBB; width: 90%;">
                        More Information
                    </div>
                  	
                </div>
                <div class="dangnhap_col">
                   <table width="100%" border="1" cellspacing="0" cellpadding="0">
  <tr>
    	<th>Tên sản phẩm</th>
        <th>Số lượng</th>
        <th>Giá</th>
  </tr>
  <? $chitietdh=$qt->get_by_thutu("donhangchitiet",-1,-1," and iddh='$id'");
  	while($row_chitietdh=mysql_fetch_assoc($chitietdh)){ ?>
  <tr>
    <td><?=$row_chitietdh['tensp']?></td>
    <td><?=$row_chitietdh['soluong']?></td>
    <td><?=$row_chitietdh['gia']?></td>
  </tr>
  <? }?>
</table>

                </div>
                
               	</form>